package com.xique.system.api.factory;

import com.xique.common.core.domain.R;
import com.xique.common.core.web.domain.PageResult;
import com.xique.system.api.RemoteSystemUserService;
import com.xique.system.api.dto.AdminListDTO;
import com.xique.system.api.dto.OperateDTO;
import com.xique.system.api.dto.SystemUserDTO;
import com.xique.system.api.model.LoginSystemUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 用户服务降级处理
 *
 * @author xique
 */
@Component
public class RemoteSystemUserFallbackFactory implements FallbackFactory<RemoteSystemUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteSystemUserFallbackFactory.class);

    @Override
    public RemoteSystemUserService create(Throwable throwable)
    {
        log.error("系统用户服务调用失败:{}", throwable.getMessage());
        return new RemoteSystemUserService()
        {
            @Override
            public R<LoginSystemUser> getUserInfo(String username) {
                return R.fail("获取系统用户失败:" + throwable.getMessage());
            }

            @Override
            public R<LoginSystemUser> getUserInfoWithUpdatePassword(String username, String password) {
                return R.fail("获取系统用户失败:" + throwable.getMessage());
            }

            @Override
            public R<String> getUserPrivateKey(String username) {
                return R.fail("获取系统用户密钥失败:" + throwable.getMessage());
            }

            @Override
            public R<List<AdminListDTO>> getAdminList() {
                return R.fail("获取操作员列表信息失败:" + throwable.getMessage());
            }

            @Override
            public R<OperateDTO> getOperate(Long operateId) {
                return R.fail("获取操作员信息失败:" + throwable.getMessage());
            }

            @Override
            public R<List<OperateDTO>> getOperateList(String operateIds) {
                return R.fail("获取操作员列表信息失败:" + throwable.getMessage());
            }

            @Override
            public R<Long> saveClientUser(SystemUserDTO dto) {
                return R.fail("新增岗亭用户失败:" + throwable.getMessage());
            }

            @Override
            public R<Boolean> removeClientUser(Long userId) {
                return R.fail("删除岗亭用户失败:" + throwable.getMessage());
            }

            @Override
            public R<PageResult> selectPageList(SystemUserDTO systemUserDTO) {
                return R.fail("分页获取岗亭用户失败:" + throwable.getMessage());
            }

            @Override
            public R<List<SystemUserDTO>> selectRoleSystemUserByUserId(Long userId) {
                return R.fail("获取同一角色下所有用户信息失败:" + throwable.getMessage());
            }
        };
    }
}
